/*============================================================================
 PROJECT: Common
 FILE:    BaseNetwork.h
 AUTHOR:  Nguyen Minh Khoai
 =============================================================================*/

/*============================================================================
 IMPORT
 =============================================================================*/

#import <Foundation/Foundation.h>
#import "AFNetworking.h"

/*============================================================================
 MACRO
 =============================================================================*/
#define kPushErrorAccessToken               @"GotoLogin"

#define kNoConnectionErrorMessage       NSLocalizedString(@"No network connection. Please check your network connection.", @"Error Message")
#define kNoServiceNotAvailable          NSLocalizedString(@"Can't connect to server. Please contact to admin.",@"Error Messeage")
#define kNoServiceFacebookAvailabel     NSLocalizedString(@"Can't get data from Facebook",@"Error Message")
#define kServiceNotAvailableMessage     NSLocalizedString(@"The network service is currently unavailable. Please try again later.", @"Error Message")
#define kErrorMessageKey                @"message"
#define kNullValueMessage               NSLocalizedString(@"Return null value", @"Error Message")
#define kAuthenticationFailedMessage    NSLocalizedString(@"Authentication failed", @"Error Message")
#define kNullResponseMessage            NSLocalizedString(@"Null response", @"Error Message")

//#define kAPIKey                         @"87cf1d955a2a69af96a38a5318b855ecf720e998"

#define kAPIKey                         @"f85de2032a485ea47fd496d0122c4e034e6f3bad958ea9739903756ee88ab0a66becdcd46c5291d3143da18895f1ea53680c1b9eaa1109df2622b44c8ca5206b"
#define kBaseService                    @"http://107.155.90.87:3000"
//#define kBaseService                    @"http://192.168.45.55:3000"



/* Header field keys */
#define kHTTP_HEADER_USER_TOKEN         @"usertoken"
#define kHTTP_HEADER_USER_INFO          @"userinfo"
#define kHTTP_HEADER_USER_LANG          @"language"
#define kHTTP_HEADER_APP_TOKEN          @"Usertoken"
#define kHTTP_HEADER_APP_ID             @"appId"
#define kHTTP_HEADER_APP_VERSION        @"version"
#define kHTTP_HEADER_APP_PIXEL_RATIO    @"X-PixelRatio"
#define kHTTP_HEADER_APP_DEVICE_ACCESS  @"X-DeviceAccess"
#define kHTTP_HEADER_TIME_ZONE          @"timezone"
#define kHTTP_HEADER_API_TOKEN          @"Apikey"

#define kExpectedPhotoSize                      CGSizeMake(600, 600)
#define kExpectedAvatarSize                     CGSizeMake(160, 160)
#define kAvatarUploadName                       @"avatar"
#define kPhotoUploadName                        @"photo"
#define kImageUploadName                        @"image"

/*============================================================================
 PRIVATE INTERFACE
 =============================================================================*/
/*----------------------------------------------------------------------------
 Interface:   BaseNetwork
 -----------------------------------------------------------------------------*/
@interface BaseNetwork : NSObject

/* properties */
@property(nonatomic, strong) AFHTTPClient *networkEngine;
@property(nonatomic, assign) BOOL enableDebugLog;

/* cancel base url */
-(void)cancelAllHTTPRequest;

/* init base url */
- (id)initWithBaseURL:(NSString *)baseUrlString;

+ (BaseNetwork *)service;

- (void)configureRequestHeaderWithUser:(id)user;

/* for normal request */
- (void)requestWithURL:(NSString *)urlString
                params:(NSMutableDictionary *)params
          successBlock:(void (^)(id))successBlock
            errorBlock:(void (^)(NSString *))errorBlock
            httpMethod:(NSString *)method;

/* for SOAP request */
- (void)requestWithHttpBody:(NSString *)httpBody
               headerFields:(NSMutableDictionary *)fields
               successBlock:(void (^)(id))successBlock
                 errorBlock:(void (^)(NSString *))errorBlock
                 httpMethod:(NSString *)method;

/* for form request */
- (void)formRequestWithURLPath:(NSString *)urlString
                        params:(NSMutableDictionary *)params
                  successBlock:(void (^)(id))successBlock
                    errorBlock:(void (^)(NSString *))errorBlock;

- (void)formRequestWithURLPath:(NSString *)urlString
                        params:(NSMutableDictionary *)params
                      filePath:(NSData *)filePath
                          name:(NSString *)name
                  successBlock:(void (^)(id))successBlock
                    errorBlock:(void (^)(NSString *))errorBlock;

- (void)formRequestWithURLPath:(NSString *)urlString
                        params:(NSMutableDictionary *)params
                         image:(UIImage *)image
                  successBlock:(void (^)(id))successBlock
                    errorBlock:(void (^)(NSString *))errorBlock
                 progressBlock:(void (^)(long long totalBytesWritten, long long totalBytesExpectedToWrite))progressBlock;

- (void)formRequestWithURLPath:(NSString *)urlString
                        params:(NSMutableDictionary *)params
                      filePath:(NSData *)photo
                      filePath:(NSData *)video
                          name:(NSString *)name
                  successBlock:(void (^)(id))successBlock
                    errorBlock:(void (^)(NSString *))errorBlock;
@end
